<!--  -->
<template>
  <div>
        <Card>
            <Form :model="formItem" :label-width="70">
                <Row :gutter="10" type="flex"  align="middle"  >
                <Col span="8">
                    <FormItem label="人员">
                        <Input v-model="formItem.name" placeholder="姓名/手机号" clearable></Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="所属客户" v-if="user_type!='01'">
                        <Select v-model="formItem.customerUuid" filterable @on-change="searchCustomerChange">
                            <Option  v-for="item in moreCustomerList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="所在机构">
                        <Input v-if="user_type!='01'" @on-focus="s_tree=true;" :disabled="!formItem.customerUuid||formItem.customerUuid=='全部'" v-model="formItem.instName" placeholder="请选择机构" readonly></Input>
                            <Input v-else @on-focus="s_tree=true;"  v-model="formItem.instName" placeholder="请选择机构" readonly></Input>
                        <!-- <Select v-if="user_type!='01'" :disabled="!formItem.customerUuid||formItem.customerUuid=='全部'" v-model="formItem.inst_uuid" filterable>
                            <Option  v-for="item in moreMechanismList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
                        </Select>
                        <Select v-else  v-model="formItem.inst_uuid" filterable>
                            <Option  v-for="item in moreMechanismList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
                        </Select> -->
                    </FormItem>
                </Col>
                <Col span="12"  >
                    <FormItem label="所在地">
                        <Cascader change-on-select v-model="search.location" placeholder="请选择省市区" :data="areasData" ></Cascader>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="注册时间">
                        <DatePicker v-model="search.timeRange" format="yyyy-MM-dd HH:mm" type="datetimerange" placement="bottom-end" placeholder="请选择开始和结束时间"></DatePicker>
                    </FormItem>
                </Col>
                </Row>
                <Row  >
                <Col span="8" offset="16"  style="text-align:right;">
                    <Button @click='handleClickgetTable' class="zh-hollow" type="primary" icon="ios-search-strong">搜索</Button>
                </Col>
                
                </Row>
            </Form>
        </Card>
        <Card style="margin-top:10px;" :padding="0">
        <Table :loading="loading" border :columns="columns" :data="data"></Table>
        <Page :current.sync="formItem.pageNumber" :total="total" show-total show-sizer @on-change="pageChange" @on-page-size-change="pageSizeChange"></Page>
        </Card>
        <Modal title="选择机构" v-model="s_tree" @on-ok="confirmST" :mask-closable="false" >
            <div style="padding:15px 30px;">
                <Tree :data="s_tree_data"   @on-select-change="s_selectChange"></Tree>
            </div>
        </Modal>
    </div>
</template>

<script>
import util from '@/libs/util.js'
import {getBankOrg,getOrgTree } from '@/libs/get.js'
import {getAwaitRepaireTable,examineRepairePeo} from '@/libs/post.js'
export default {
    name:'',
    data () {
        return {
            s_select_op:[],
			s_tree_data:[],
			s_tree:false,
            btnp:{},
            btn:{
                dshbxren_sh:false
            },
            userUuid:'',
            user_type:'',
            loading:true,
            total:0,
            search:{
                location:[],
                timeRange:[]
            },
            formItem:{
                name:'',
                customerUuid:'全部',
                inst_uuid:'全部',
                instName:'',
                pageNumber:1,
                pageSize:10,
                province:'',
                city:'',
                district:'',
                startTime:'',
                endTime:'' 
            },
            moreCustomerList:[],
            moreMechanismList:[{name:'全部',uuid:'全部'}],
            areasData:this.$store.state.user.areaData ,              
            columns:[
                {
                    key:'name',
                    title:'姓名',
                    fixed:'left',
                    minWidth:100
                },
                {
                    key:'mobile',
                    title:'手机号',
                    align:'center',
                    minWidth:130
                },
                {
                    key:'addr',
                    title:'所在地',
                    minWidth:170
                },
                {
                    key:'bank_name',
                    title:'所属客户',
                    minWidth:150
                },
                {
                    key:'inst_name',
                    title:'所在机构',
                    minWidth:120
                },
                {
                    key:'time',
                    title:'注册时间',
                    align:'center',
                    minWidth:150
                },
                {
                    key:'action',
                    title:'操作',
                    align:'center',
                    fixed:'right',
                    minWidth:80,
                    render:(h,params)=>{
                        let uuid=params.row.uuid;
                        return h('div',[
                            h('Button',{
                                props:{
                                type:'text',
                                size:'small'
                                },
                                style:{
                                color:'#2D8CF0',
                                display:this.btnp.dshbxren_sh?'inline-block':'none'
                                },
                                on:{
                                click:()=>{
                                    let config={
                                    title:'审核人员',
                                    content:'是否通过该人员的注册申请？',
                                    okText:'通过',
                                    cancelText:'拒绝',
                                    closable:true,
                                    onOk:()=>{
                                        this.examine(uuid,0)
                                    },
                                    onCancel:()=>{
                                        this.examine(uuid,3)
                                    }
                                    }
                                    this.$Modal.confirm(config)
                                    
                                }
                                }
                            },'审核')
                        ])
                    }
                }
            ]    ,
            data:[]  
        };
    },
    methods:{
        init(){
            let that=this;
            util.isCustomer(this);
            let timer;
			if(that.user_type!=='01'){
				timer=setInterval(()=>{
					if(that.$store.state.user.customer.length>0){
						that.moreCustomerList=[{name:'全部',uuid:'全部'},...that.$store.state.user.customer];
						clearInterval(timer)	
					}
				},500);
			}else{
				this.searchCustomerChange(this.userUuid);	
			}
            // setTimeout(()=>{
            //     //that.areasData=that.$store.state.user.areaData;
            //     if(this.user_type!=='01'){
            //         that.moreCustomerList=[{name:'全部',uuid:'全部'},...that.$store.state.user.customer];
            //     }
            // },5000);
            // if(this.user_type=='01'){               
            //     this.newSearchCustomerChange(this.userUuid,'search');    
            // } 
        },
        async getSearchInstTree(value){
            this.formItem.inst_uuid='';
            this.formItem.instName='';
            this.s_select_op=[];
			if(value!=='全部'){
				let res=await getOrgTree(value);
				let response=res.data;
				if(response.code===200){
					this.s_tree_data=util.tree([response.data]);
				}else{
					this.$Notice.error({
						title: '获取机构失败',
						desc:response.msg
					});
				}
			}
		},
		s_selectChange(selectarr){
			this.s_select_op=selectarr;
		},
		confirmST(){
			if(this.s_select_op.length>0){
				this.formItem.inst_uuid=this.s_select_op[0].value;
				this.formItem.instName=this.s_select_op[0].title;
			}else{
				this.formItem.inst_uuid='';
				this.formItem.instName='';
			}
		},
        async examine(uuid,state){
            let res=await examineRepairePeo({uuid,state});
            let response=res.data;
            if(response.code===200){
                this.$Notice.success({
                    desc:state=='0'?'已通过':'已拒绝'
                })
                this.formItem.pageNumber=1;
                this.getTable();
            }else{
                this.$Notice.error({
                title: '请求出错',
                desc:response.msg
                });
                return false
            }
        },
        async getTable(){
            this.loading=true;
            let form=JSON.parse(JSON.stringify(this.formItem));
            for(let key in form){
                if(form[key]==='全部'){
                form[key]='';
                }
            }
            if(!!this.search.timeRange[0]&&this.search.timeRange.length>0){
                form.startTime=util.time1(this.search.timeRange[0]);
                form.endTime=util.time1(this.search.timeRange[1]);
            }else{
                form.startTime='';
                form.endTime='';
            }
            if(this.search.location.length>0&&!!this.search.location[0]){
                form.province=this.search.location[0];
                form.city=this.search.location[1];
                form.district=this.search.location[2];
            }else{
                form.province='';
                form.city='';
                form.district='';
            }
           
            let res=await getAwaitRepaireTable(form);
            let response=res.data;
            if(response.code===200){
                this.total=response.data.total;
                this.data=response.data.rows.map(item=>{
                    item.time=item.created.slice(0,16);
                    return item
                });
                this.loading=false;
            }else{
                this.$Notice.error({
                title: '失败',
                desc:response.msg
                });
               
            }
        },
        handleClickgetTable(){
            this.formItem.pageNumber=1;
            this.getTable();
        },
        pageSizeChange(size){
        //回到第一页
            this.formItem.pageNumber=1;
            this.formItem.pageSize=size;
            this.getTable();
        },
        pageChange(number){
            this.pageNumber=number;
            this.getTable();
        },
        async actionPower(){
            let res=await getPower();
            let response=res.data;
            if(response.code===200){
                this.powerList=response.data;
            }else{
                this.$Notice.error({
                title: '请求出错',
                desc:response.msg
                });
            }
        },
        async searchCustomerChange(value){
            this.getSearchInstTree(value);
            //await this.newSearchCustomerChange(value,'search')
        },
        async newSearchCustomerChange(value,type){
            if(value!=='全部'){
                let res =await getBankOrg(value,'','','')
                if(res.status===200){
                    let response=res.data;
                    if(response.code===200){
                        if(type==='search'){
                        this.moreMechanismList=[{uuid:'全部',desc:'全部'},...response.data]
                        }else if(type==='form'){
                        this.mechanismList=response.data
                        }                          
                    }else{
                        this.$Notice.error({
                            title: '请求出错',
                            desc:response.msg
                        });
                    }
                }else{
                    this.$Notice.error({
                        title: '请求失败'
                    });
                } 
            }
        },
    },
    created(){
        this.init();
        this.getTable();
        this.btnp=util.bpower(this,this.btn);
    }

}

</script>
<style lang='scss' >
</style>